import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { retry } from 'rxjs/operators';
import { LAUNCH_ALI_PAY, LAUNCH_PAY, PAY_BY_BALANCE, PAY_WAIT, PAY_WAIT_ALIPAY } from 'src/app/api/fee-enquiry/pay';

@Injectable({providedIn: 'root'})
export class PayService {
  constructor(
    private http: HttpClient
  ) { }
  
  // {
  //   "productName":"增城自来水公司缴费",
  //   "totalFee":"1",  //单位：分
  //   "usageCode":"00010129"
  //  }
  _launchPay(data: any){
    return this.http.post(LAUNCH_PAY, data)
  }
  _launchAliPay(data: any){
    return this.http.post(LAUNCH_ALI_PAY, data)
  }
  // 预付费抵扣
  _payByBalance(data: any){
    return this.http.post(PAY_BY_BALANCE, data)
  }


  _payWaiting(outTradeNo: string, type = 'weChatPay'){
    let url = PAY_WAIT
    if(type === 'ALiPay'){
      url = PAY_WAIT_ALIPAY
    }
    return this.http.get(url + outTradeNo, {responseType: 'text'}).pipe(retry(3))
  }
}